<?php

class Install extends Controller {

	function Install()
	{
		parent::Controller();	
	}
	
	function index()
	{
	
		$this->load->dbforge();
		
		//$this->dbforge->create_database('cartSpiral'); //Renamble Database D:
		
		//Attribute-Value Table
		$fields = array(
                    'id' => array(
                                             'type' => 'INT',
                                             'constraint' => 9,
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE
                                      ),
                    'attribute_id' => array(
                                             'type' => 'INT',
                                             'constraint' => 9,
                                      ),
                    'value' => array(
                                             'type' =>'VARCHAR',
                                             'constraint' => '45',
                                      ),
		          );   
	    $this->dbforge->add_key('id', TRUE);     
	    $this->dbforge->add_field($fields);
		$this->dbforge->create_table('attributes_values', TRUE);
		
		//Attribute Table
		$fields = array(
                    'id' => array(
                                             'type' => 'INT',
                                             'constraint' => 9,
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE
                                      ),
                    'name' => array(
                                             'type' => 'VARCHAR',
                                             'constraint' => '45',
                                      ),
                    'type' => array(
                                             'type' =>'VARCHAR',
                                             'constraint' => '10',
                                      ),
		          );   
	    $this->dbforge->add_key('id', TRUE);
	    $this->dbforge->add_field($fields);
		$this->dbforge->create_table('attributes', TRUE);

		//Category Table
		$fields = array(
                    'id' => array(
                                             'type' => 'INT',
                                             'constraint' => 9,
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE
                                      ),
                    'name' => array(
                                             'type' => 'VARCHAR',
                                             'constraint' => '45',
                                      ),
                    'subcat' => array(
                                             'type' =>'INT',
                                             'constraint' => 9,
                                      ),
		          );   
	    $this->dbforge->add_key('id', TRUE);
	    $this->dbforge->add_field($fields);   
		$this->dbforge->create_table('category', TRUE);
		
		//Class Table
		$fields = array(
                    'id' => array(
                                             'type' => 'INT',
                                             'constraint' => 9,
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE
                                      ),
                    'name' => array(
                                             'type' => 'VARCHAR',
                                             'constraint' => '45',
                                      ),
                    'subcat' => array(
                                             'type' =>'INT',
                                             'constraint' => 9,
                                      ),
		          );   
	    $this->dbforge->add_key('id', TRUE);
	    $this->dbforge->add_field($fields);  
		$this->dbforge->create_table('class', TRUE);

		//Invoice Table
		$fields = array(
                    'id' => array(
                                             'type' => 'INT',
                                             'constraint' => 9,
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE
                                      ),
                    'date' => array(
                                             'type' => 'VARCHAR',
                                             'constraint' => '45',
                                      ),
                    'user_id' => array(
                                             'type' => 'VARCHAR',
                                             'constraint' => '45',
                                      ),
                    'item_name' => array(
                                             'type' =>'VARCHAR',
                                             'constraint' => '45',
                                      ),
                    'item_cost' => array(
                                             'type' =>'INT',
                                             'constraint' => 9,
                                      ),
                    'quantity_bought' => array(
                                             'type' =>'INT',
                                             'constraint' => 9,
                                      ),
                    'status' => array(
                                             'type' =>'INT',
                                             'constraint' => 9,
                                      ),
		          );   
	    $this->dbforge->add_key('id', TRUE);
	    $this->dbforge->add_field($fields); 
		$this->dbforge->create_table('invoice', TRUE);
		
		//Invoice_Status Table
		$fields = array(
                    'id' => array(
                                             'type' => 'INT',
                                             'constraint' => 9,
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE
                                      ),
                    'name' => array(
                                             'type' => 'VARCHAR',
                                             'constraint' => '45',
                                      ),
		          );   
	    $this->dbforge->add_key('id', TRUE);
	    $this->dbforge->add_field($fields);     
		$this->dbforge->create_table('invoice_status', TRUE);
		
		//Item Table
		$fields = array(
                    'id' => array(
                                             'type' => 'INT',
                                             'constraint' => 9,
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE
                                      ),
                    'name' => array(
                                             'type' => 'VARCHAR',
                                             'constraint' => '45',
                                      ),
                    'stock' => array(
                                             'type' => 'INT',
                                             'constraint' => 9,
                                      ),
                    'price' => array(
                                             'type' => 'INT',
                                             'constraint' => 9,
                                      ),
                    'class' => array(
                                             'type' => 'INT',
                                             'constraint' => 9,
                                      ),
		          );   
	    $this->dbforge->add_key('id', TRUE);
	    $this->dbforge->add_field($fields);  
		$this->dbforge->create_table('item', TRUE);

		//link_cat Table
		$fields = array(
                    'id' => array(
                                             'type' => 'INT',
                                             'constraint' => 9,
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE
                                      ),
                    'cat_id' => array(
                                             'type' => 'INT',
                                             'constraint' => 9,
                                      ),
                    'product_id' => array(
                                             'type' => 'INT',
                                             'constraint' => 9,
                                      ),
		          );   
	    $this->dbforge->add_key('id', TRUE);
	    $this->dbforge->add_field($fields);     
		$this->dbforge->create_table('link_cat', TRUE);


		
		//link_class Table
		$fields = array(
                    'id' => array(
                                             'type' => 'INT',
                                             'constraint' => 9,
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE
                                      ),
                    'class_id' => array(
                                             'type' => 'INT',
                                             'constraint' => 9,
                                      ),
                    'attribute_id' => array(
                                             'type' => 'INT',
                                             'constraint' => 9,
                                      ),
		          );   
	    $this->dbforge->add_key('id', TRUE);
	    $this->dbforge->add_field($fields);    
		$this->dbforge->create_table('link_class', TRUE);

		//link_desc Table
		$fields = array(
                    'id' => array(
                                             'type' => 'INT',
                                             'constraint' => 9,
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE
                                      ),
                    'type' => array(
                                             'type' => 'VARCHAR',
                                             'constraint' => '45',
                                      ),
                    'type_id' => array(
                                             'type' => 'INT',
                                             'constraint' => 9,
                                      ),
                    'text' => array(
                                             'type' => 'TEXT',
                                      ),
		          );   
	    $this->dbforge->add_key('id', TRUE);
	    $this->dbforge->add_field($fields);    
		$this->dbforge->create_table('link_desc', TRUE);

		//require Table
		$fields = array(
                    'id' => array(
                                             'type' => 'INT',
                                             'constraint' => 9,
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE
                                      ),
                    'require_name' => array(
                                             'type' => 'VARCHAR',
                                             'constraint' => '45',
                                      ),
                    'require_type' => array(
                                             'type' => 'VARCHAR',
                                             'constraint' => '45',
                                      ),
		          );
		$this->dbforge->add_key('id', TRUE);
		$this->dbforge->add_field($fields);    
		$this->dbforge->create_table('require', TRUE);
		
		//user Table
		$fields = array(
                    'id' => array(
                                             'type' => 'INT',
                                             'constraint' => 9,
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE
                                      ),
                    'first' => array(
                                             'type' => 'VARCHAR',
                                             'constraint' => '45',
                                      ),
                    'last' => array(
                                             'type' => 'VARCHAR',
                                             'constraint' => '45',
                                      ),
                    'email' => array(
                                             'type' => 'VARCHAR',
                                             'constraint' => '45',
                                      ),
                    'pass' => array(
                                             'type' => 'VARCHAR',
                                             'constraint' => '77',
                                      ),
		          );
		$this->dbforge->add_key('id', TRUE);
		$this->dbforge->add_field($fields);    
		$this->dbforge->create_table('user', TRUE);
		
		//user_address Table
		$fields = array(
                    'id' => array(
                                             'type' => 'INT',
                                             'constraint' => 9,
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE
                                      ),
                    'address_type' => array(
                                             'type' => 'VARCHAR',
                                             'constraint' => '45',
                                      ),
                    'address_name' => array(
                                             'type' => 'VARCHAR',
                                             'constraint' => '45',
                                      ),
                    'first' => array(
                                             'type' => 'VARCHAR',
                                             'constraint' => '45',
                                      ),
                    'last' => array(
                                             'type' => 'VARCHAR',
                                             'constraint' => '77',
                                      ),
                    'street' => array(
                                             'type' => 'VARCHAR',
                                             'constraint' => '45',
                                      ),
                    'post' => array(
                                             'type' => 'VARCHAR',
                                             'constraint' => '45',
                                      ),
                    'city' => array(
                                             'type' => 'VARCHAR',
                                             'constraint' => '77',
                                      ),
                    'state' => array(
                                             'type' => 'VARCHAR',
                                             'constraint' => '77',
                                      ),
                    'country' => array(
                                             'type' => 'VARCHAR',
                                             'constraint' => '77',
                                      ),
		          );
		$this->dbforge->add_key('id', TRUE);
		$this->dbforge->add_field($fields);    
		$this->dbforge->create_table('user_address', TRUE);
		
		//user_contact Table
		$fields = array(
                    'id' => array(
                                             'type' => 'INT',
                                             'constraint' => 9,
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE
                                      ),
                    'user_id' => array(
                                             'type' => 'INT',
                                             'constraint' => 9,
                                      ),
                    'contact_type' => array(
                                             'type' => 'VARCHAR',
                                             'constraint' => '45',
                                      ),
                    'contact_name' => array(
                                             'type' => 'VARCHAR',
                                             'constraint' => '45',
                                      ),
                    'value' => array(
                                             'type' => 'INT',
                                             'constraint' => 9,
                                      ),
		          );
		$this->dbforge->add_key('id', TRUE);
		$this->dbforge->add_field($fields);    
		$this->dbforge->create_table('user_contact', TRUE);

		//the Database has been created... though we havent made sure if we could connect to it...
		//Lets Create the Tables but first lets check it
		/////////if they exist, check for version otherwise don't update
		//then redirect
		echo 'Success!';

	}
}

/* End of file front.php */
/* Location: ./system/application/controllers/front.php */